package com.ranjiaqi.output;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName TestInputStream
 * @Description TODO
 * @Author hp
 * @Date 2021/7/1 11:12
 * @Version 1.0
 **/
public class TestInputStream {
    public static void main(String[] args) throws IOException {
        /*readTest();*/
        TestArrayInputStream();
    }

   /* public static void readTest() throws IOException {
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream("F:/java/1.txt");
            int x = 0;
            while ((x = inputStream.read()) != -1) {
                System.out.print((char) inputStream.read());
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStream != null)
                    inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }*/

   public static void TestArrayInputStream(){
       try (InputStream inputStream = new FileInputStream("F:/java/1.txt")){
           byte[] byets = new byte[1024];
           int x = 0;
           while ((x = inputStream.read(byets))!=-1){
               System.out.println(new String(byets,0,x));
           }
       }catch (IOException e ){
           e.printStackTrace();
       }
   }
}
